package toster;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *Takes the input file, formats it, and sends it to the preprossesor
 * e.g. gets the party started
 * @author zach
 */
public class Driver {
    private int[][] horz;
    private int[][] vert;
    private boolean toggle=true;
    public ArrayList<String[]> inData=new ArrayList<String[]>();
    public String name;

    /**
     * The constructor is initializing a scanner which scans the File given in
     * the parameter.  It scans the first String of the File and if the first
     * String is "BREAK" it switches from horrizontal to vertical rulesets.  It
     * then passes all the information it gathered on the the preproccessor.
     * @param inf
     * @throws FileNotFoundException
     *
     */
    public Driver(File inf) throws FileNotFoundException{
        Scanner in=new Scanner(inf);
        boolean first_line=true;

        while(in.hasNextLine()){
            if(first_line){
                name=in.nextLine();
                first_line=!first_line;
            }else
            inData.add(in.nextLine().split(" "));
        }
       
        int zig=0;
        for(String[] i:inData){
            if(i[0].equals("BREAK")){
                break;
            }
            zig++;

        }
        horz=new int[zig][];
        vert=new int[inData.size()-zig-1][];
        zig=0;

        for(String[] i:inData){
            if(i[0].trim().equals("BREAK")){
                toggle=!toggle;
                zig=0;
                continue;
            }
            int yyz=0;
            if (toggle) horz[zig]=new int[i.length];
            else vert[zig]=new int[i.length];
            for(String o:i){
                if(toggle) 
                    horz[zig][yyz]=Integer.parseInt(o);
                else 
                    vert[zig][yyz]=Integer.parseInt(o);
                yyz++;
            }
            zig++;
        }
        new PreProssesor(horz,vert);
    }

}